<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" href="../../libs/mui.min.css"/>
    <!--<link rel="stylesheet" type="text/css" href="../../libs/app.css" />-->
    <link rel="stylesheet" href="../../css/main.css"/>
    <link rel="stylesheet" href="../../css/small.css"/>
</head>

<body>
<div class="head">
    <img class="mui-action-back" src="../../images/all-left.png" alt="">
    <p>小额贷款</p>
</div>
<div class="context" id="context">
    <!--<div class="context-d">
    <div class="left">
        <p>1,000</p><p>最高额度（元)</p>
    </div>
    <div class="middle">
        <p><span>12</span>小时放款</p>
        <p>月费率<span>3</span></p>
        <p>贷款期限<span>3-6</span>个月</p>
    </div>
    <div class="right">
        <button id="s-askfor" onclick="href('s-askfor.html','s-askfor')">申请贷款</button>
    </div>
</div>-->
    <!--<p class="more">点击加载更多</p>-->
</div>
<script src="../../libs/mui.min.js"></script>
<script src="../../js/jquery-3.1.1.min.js"></script>
<script src="../../js/url.js"></script>
<script>
    localStorage.dk_type = 'xed';
    addsmall();
    mui.init()
    var page = 1;

    //小额贷款接口
    function addsmall() {
        $.ajax({
            url: ur + 'rest/smallLoanController/list',
            type: 'GET',
            dataType: 'json',
            headers: {
                "X-Token": localStorage.token
            },
            data: {
                page: page
            }
        })
            .done(function (data) {
                var s = data.data.list.length;
                var totalPage = Math.ceil(data.data.total / 10);
                if (data.meta.code == 'S002') {
                    if (totalPage >= page) {
                        for (var i = 0; i < s; i++) {
                            var list = '<div class="context-d" id=' + data.data.list[i].id + '>' +
                                '<div class="left">' +
                                '<p>' + data.data.list[i].maxAmount + '</p><p>最高额度（元)</p>' +
                                '</div>' +
                                '<div class="middle">' +
                                '<p>' + data.data.list[i].name + '</p>' +
                                '<p>月利率<span>' + data.data.list[i].dayPoundage + '%</span></p>' +
                                '<p>贷款期限<span>' + data.data.list[i].minLoanTerm + '-' + data.data.list[i].maxLoanTerm + '</span>月</p>' +
                                '</div>' +
                                '<div class="right">' +
                                '<button class="s-askfor" herf="' + data.data.list[i].link + '">申请贷款</button></div></div>';
                            $('#context').append(list);
                        }
                    }
                    var more = '<p class="more">点击加载更多</p>';
                    if (page < totalPage && $('.more').length == 0) {
                        $('#context').append(more);
                        $('.more').text('点击加载更多');
                        $('#context').on('tap', '.more', function () {
                            page++;
                            $(this).remove()
                            addsmall();
                        })
                    } else {
                        $('#context').append(more);
                        $('.more').text('已无更多。');
                    }
                } else {
                    mui.toast(data.meta.message);
                }
            })
    }

    //页面跳转
    $('#context').on('tap', '.s-askfor', function () {
        var $this = $(this);
        localStorage.swiper_id = $this.attr('herf');
        if ($this.attr('herf') == '' || $this.attr('herf') == 'null') {
            localStorage.xed_id = $this.attr('id');
            href('s-askfor.html', 's-askfor.html');
        } else {
            href('swiper-news.html', 'swiper-news');
        }
    })
</script>
</body>

</html>